#include <stdio.h>
#include <stdlib.h>
int eval_plus (char *arg[]);
int eval_times (char *arg[]);
int main(int argc, char *argv[])
{
  char** current = argv;
  while (*current != 0)
   {
     current++;
   }
  // we are now at the end;
  int operationstack[1000];  //1 for *
                             //2 for +
  int current_op=0;
  
  current --;

  int outcome=0;

  while  (argc != 0)
  {
    switch ((int)*current[0])
      {
      case '*':
        operationstack[current_op]=2;
        current--;
        argc--;
        current_op++;
        continue;
      case '+':
        operationstack[current_op]=1;
        current--;
        argc--;
        current_op++;
        continue;
      case '0':
      case '1':
      case '2':
      case '3':
      case '4':
      case '5':
      case '6':
      case '7':
      case '8':
      case '9':
       if (outcome!=0) //something in the accumulator, we only need one number.
         {
           if (current_op !=0) //we need to do something to it.
             {
               current_op--;
               if (operationstack[current_op] == 2)
                 // *
                 {
                   outcome=outcome*atoi(*current);
                   current--;
                   argc--;
                   continue;
                 }
               if (operationstack[current_op] == 1) // +
                 {
                   outcome=outcome+atoi(*current);
                   current--;
                   argc--;
                   continue;
                 }
             }
           else
             {
               // we keep the most recent number
               outcome=atoi(*current);
               argc--;
               current--;
               continue;
             }
         }
        else
          {
             // first number
             outcome=atoi(*current);
             argc--;
             current--;
             continue;

          }
       
        printf ("%s ascii outcome \n" , *current);        
        printf ("%d current op \n" , current_op);
        argc--;
        current--;
      default:
        printf ("final outcome: %d \n",outcome);
        //        printf ("current %s \n",*current);
        argc--;
        current--;        
        break;
      }
  }

  return (0);
}



int eval_times (char *arg[])
{
  return 0;
  //check if -1 argument is *
  //check if -1 argument is +
  //check if -1 argument is a number
  
}


int eval_plus (char *arg[])
{
  return 0;
}
